home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / SAT 2.3b4 / Demo ƒ / OffscreenToys SAT demo ƒ / SAT_OT.p < prev   
Text File  |  1995-04-20  |  12KB  |  263 lines

  1. unit SAT_OT;
  2.  
  3. interface
  4. {$ifc UNDEFINED THINK_PASCAL}
  5.     uses
  6.         Types, QuickDraw, Icons; {Icons assume UPI}
  7. {$endc}
  8.  
  9.     type
  10.         {BMPtr = ^BitMap;}
  11.  
  12.         SATPort = record
  13.                 port: GrafPtr;
  14.                 device: GDHandle;
  15.                 rows: Ptr;
  16.                 bounds: Rect;
  17.                 baseAddr: Ptr;
  18.                 rowBytes: Integer;
  19.             end;
  20.         SATPortPtr = ^SATPort;
  21.  
  22.         FacePtr = ^Face;
  23.         Face = record
  24.                 colorData: Ptr;
  25.                 resNum: integer;
  26.                 iconMask: BitMap;
  27.                 rowBytes: integer;
  28.                 next: FacePtr;
  29.                 maskRgn: RgnHandle;
  30.                 rows, maskRows: Ptr;
  31.                 redrawProc: ProcPtr;    {Called on depth changes, not needed if loaded from a cicn}
  32.             end;
  33.  
  34.         SpritePtr = ^Sprite;
  35.         Sprite = record
  36. { Variables that you should change as appropriate }
  37.                 kind: Integer; { Used for identification. >0: friend. <0 foe }
  38.                 position: Point;
  39.                 hotRect, hotRect2: Rect; { Tells how large the sprite is; hotRect is centered around origo }
  40.                                         {hotRect is set by you. hotRect2 is offset to the current position.}
  41.                 face: FacePtr; { Pointer to the Face (appearance) to be used. }
  42.                 task: ProcPtr; { Callback-routine, called once per frame. If task=nil, the sprite is removed. }
  43.                 hitTask: ProcPtr; { Callback in collisions. }
  44.                 destructTask: ProcPtr; { Called when a sprite is disposed. (Usually nil.) }
  45.                 clip: RgnHandle; {Clip region to be used when this sprite is drawn.}
  46. { SAT variables that you shouldn't change: }
  47.                 oldpos: Point;                {The 'task' routine is not allowed to change this! }
  48.                 next, prev: SpritePtr;    {You may change them in your own sorting routine, but be careful if you do.}
  49.                 r, oldr: Rect;                {Rectangle telling where to draw. Avoid messing with it.}
  50.                 oldFace: FacePtr;            {Used by RunSAT2}
  51.                 dirty: Boolean;            {Used by RunSAT2}
  52. {Variables for internal use by the sprites. Use as you please. Edit as necessary - this is merely a default}
  53. {set, enough space for most cases - but if you change the size of the record, call SetSpriteSize immediately}
  54. {after initializing (before any sprites are created)!}
  55.                 layer: integer; {For layer-sorting. When not used for that, use freely.}
  56.                 speed: Point; { Can be used for speed, but not necessarily. }
  57.                 mode: integer; { Usually used for different modes and/or to determine what image to show next. }
  58.                 fixedPos: Point; {Fixed-point position}
  59.                 appLong: Longint; {Longint for free use by the application.}
  60.             end;
  61.  
  62. {Type for SATs pattern utilities.}
  63.     type
  64.         SATPattern = record
  65.                 patternType: integer; {1 = Pattern, PatHandle, 2 = PixPat, PixPatHandle}
  66.                 thePat: PixPatHandle; {or PatHandle}
  67.             end; {record}
  68.         SATPatPtr = ^SATPattern;
  69.         SATPatHandle = ^SATPatPtr;
  70.  
  71. {Update list. Used internally}
  72.         UpdatePtr = ^UpdateRec;
  73.         UpdateRec = record
  74.                 updateRect: Rect;
  75.                 next: UpdatePtr;
  76.             end;
  77.  
  78. {The globals record. Some fields are important for you. These are marked with *}
  79.         SATglobalsRec = record
  80.                 wind: SATPort;                                {*The window that SAT draws in. You get the WindowPtr as gSAT.wind.port}
  81.                 offSizeH, offSizeV: integer;                    {*Offscreen size, used to limit sprite positions}
  82.                 offScreen: SATPort;                            {*Offscreen image }
  83.                 backScreen: SATPort;                        {*Background image }
  84.  
  85.                 ox, oy: longint;                                {Internal}
  86.                 pict, bwpict: integer;                        {PICT id's}
  87.                 fitThePICTs: boolean;                        {Resize PICTs to fit?}
  88.                 sorting: integer;                                {Chosen sorting}
  89.                 collision: integer;                            {Chosen collision handling}
  90.                 searchWidth: integer;                        {Chosen search width}
  91.                 screen: PixMapHandle;                        {Internal}
  92.                 bounds: Rect;                                    {Internal}
  93.                 initDepth: Integer;                            {*Depth at last icon initialization}
  94.                 synchHook: ProcPtr;                            {Synch procedure}
  95.                 sRoot: SpritePtr;                                {Sprite list root}
  96.                 updateRoot: UpdatePtr;                        {Update list root}
  97.                 anyMonsters: Boolean;                        {*False when no sprites with kind < -1 are active }
  98.  
  99.                 ditherOff: CGrafPtr;                            {Internal}
  100.                 ditherOffGD: GDHandle;                        {Internal}
  101.                 iconPort: SATPort;                            {Internal}
  102.                 iconPort2: SATPort;                            {Internal}
  103.                 bwIconPort: GrafPtr;                         {Internal}
  104. {Environment-independent globals:}
  105.                 faceRoot: FacePtr;                            {Root of face list}
  106.                 colorFlag: Boolean;                            {True if color QuickDraw is available.}
  107. {Blitters! You should not change these fields yourself. (Possibly for installing a blitter in your program code.)}
  108.                 rectBlit1, maskBlit1: ProcPtr;                {Supplied - this is either RBlt/MBlt 0 or 1}
  109.                 rectBlit2, maskBlit2: ProcPtr;                {Will probably never be used}
  110.                 rectBlit4, maskBlit4: ProcPtr;                {Supplied}
  111.                 rectBlit8, maskBlit8: ProcPtr;                {Supplied}
  112.                 rectBlit16, maskBlit16: ProcPtr;            {Not supplied}
  113.                 rectBlit32, maskBlit32: ProcPtr;            {Not supplied}
  114.                 curRectBlit, curMaskBlit: ProcPtr;            {Currently selected fast blitter}
  115.             end;
  116.  
  117. {Configuration types: VPositionSort and KindCollision are defaults.}
  118.     const
  119. {Sorting options}
  120.         kVPositionSort = 0;
  121.         kLayerSort = 1;
  122.         kNoSort = 2;
  123. {Collision detection options}
  124.         kKindCollision = 0;
  125.         kForwardCollision = 1;
  126.         kBackwardCollision = 2;
  127.         kNoCollision = 3;
  128.         kForwardOneCollision = 4;
  129.  
  130.     var
  131. {$ifc UNDEFINED THINK_PASCAL}
  132.         gSAT: SATglobalsRec;
  133.         external;                {Most globals in a record. See above.}
  134.         gSATSoundErrorProc: ProcPtr;
  135.         external;        {Pointer to procedure to call on sound error.}
  136. {$elsec}
  137. {$J+}
  138.         gSAT: SATglobalsRec;                {Most globals in a record. See above.}
  139.         gSATSoundErrorProc: ProcPtr;        {Pointer to procedure to call on sound error.}
  140. {$J-}
  141. {$endc}
  142.  
  143. {Initializing and customizing}
  144.     procedure SATConfigure (PICTfit: boolean; newSorting, newCollision, searchWidth: integer);
  145.     procedure SATInit (pictID, bwpictID, Xsize, Ysize: integer);
  146.     procedure SATCustomInit (pictID, bwpictID: integer; var SATdrawingArea: Rect; {}
  147.                                     preloadedWind: WindowPtr; chosenScreen: GDHandle; useMenuBar, {}
  148.                                     centerDrawingArea, fillScreen, dither4bit, beSmart: Boolean);
  149. {Maintainance, background manipulation etc.}
  150.     function SATDepthChangeTest: Boolean;
  151.     procedure SATDrawPICTs (pictID, bwpictID: integer);
  152.     procedure SATRedraw;
  153. {Drawing}
  154.     procedure SATPlotFace (theFace: FacePtr; theGrafPtr: SATPortPtr; where: Point; Fast: boolean);
  155.     procedure SATPlotFaceToScreen (theFace: FacePtr; where: Point; Fast: boolean);
  156. {SATCopybits is now only done with a CopyBits - so it's really obsolete.}
  157.     procedure SATCopyBits (src, dest: SATPortPtr; {}
  158.                                     var srcRect, destRect: Rect; fast: Boolean);
  159.     procedure SATCopyBitsToScreen (src: SATPortPtr; var srcRect, destRect: Rect; fast: Boolean);
  160.     procedure SATBackChanged (var r: Rect); {Tell SAT about changes in backScreen}
  161. {SetPort replacements}
  162.     procedure SATGetPort (var port: SATPort);
  163.     procedure SATSetPort (var port: SATPort);
  164.     procedure SATSetPortOffScreen; {Use before using QuickDraw on offScreen}
  165.     procedure SATSetPortBackScreen; {Use before using QuickDraw on backScreen}
  166.     procedure SATSetPortScreen; {Use to set port to gSAT.wind}
  167. {Basic sprite handling}
  168.     function SATGetFace (resNum: integer): FacePtr;
  169.     procedure SATDisposeFace (theFace: FacePtr);
  170.     function SATNewSprite (kind, hpos, vpos: integer; setup: ProcPtr): SpritePtr;
  171.     function SATNewSpriteAfter (afterthis: SpritePtr; kind, hpos, vpos: integer; setup: ProcPtr): SpritePtr;
  172.     procedure SATKillSprite (who: Spriteptr);
  173. {Animating}
  174.     procedure SATRun (fast: Boolean); {The heart of the whole package!}
  175.     procedure SATRun2 (fast: Boolean); {Alternate routine for allowing resting sprites}
  176. {Special functions for advanced programmers}
  177.     procedure SATInstallSynch (theSynchProc: ProcPtr);
  178.     procedure SATInstallEmergency (theEmergencyProc: ProcPtr);
  179.     procedure SATSetSpriteRecSize (theSize: longint);
  180.     procedure SATSkip;
  181.     procedure SATKill; {Dispose of offscreen buffers to allow re-init}
  182.     procedure SATWindMoved;
  183. {Offscreen - use only if you need an *extra* offscreen buffer. These calls are likely to change in the future!}
  184.     procedure SATMakeOffscreen (var portP: SATPort; var rectP: Rect); {Make offscreen buffer in current screen depth and CLUT.}
  185.     procedure SATDisposeOffScreen (var portP: SATPort); {Get rid of offscreen}
  186.     function CreateOffScreen (var bounds: Rect; depth: Integer; colors: CTabHandle; var retPort: CGrafPtr; var retGDevice: GDHandle): OSErr; {From Principia Offscreen - color only}
  187.     procedure DisposeOffScreen (doomedPort: CGrafPtr; doomedGDevice: GDHandle);{From Principia Offscreen - color only}
  188. {Face manipulation (for advanced programmers)}
  189.     procedure SATSetPortMask (theFace: FacePtr);
  190.     procedure SATSetPortFace (theFace: FacePtr);
  191.     procedure SATSetPortFace2 (theFace: FacePtr);
  192.     function SATNewFace (var faceBounds: Rect): FacePtr;
  193.     procedure SATChangedFace (theFace: FacePtr);
  194.  
  195. {New procedures, EXPERIMENTAL, intended for making a C++ interface}
  196.     function SATGetFacePP (resNum: integer; fStorage: Ptr): FacePtr;
  197.     function SATNewSpritePP (afterthis: SpritePtr; sStorage: Ptr; theKind, hpos, vpos: integer; setup: ProcPtr): SpritePtr;
  198.     procedure SATCopySprite (destSprite: SpritePtr; srcSprite: SpritePtr);
  199.     function SATNewFacePP (var faceBounds: Rect; fStorage: Ptr): FacePtr;
  200.     procedure SATCopyFace (destFace: FacePtr; srcFace: FacePtr);
  201.     procedure SATDisposeFacePP (theFace: FacePtr);
  202.  
  203. {Cicn utilities}
  204.     function SATGetCicn (cicnId: integer): CIconHandle;
  205.     procedure SATPlotCicn (theCicn: CIconHandle; dest: GrafPtr; destGD: GDHandle; var r: Rect); {Borde jag lägga till device?}
  206.     procedure SATDisposeCicn (theCicn: CIconHandle);
  207.  
  208. {Utilities}
  209.     procedure SATSetStrings (ok, yes, no, quit, memerr, noscreen, nopict, nowind: Str255);
  210.     function SATTrapAvailable (theTrap: Integer): Boolean;
  211.     procedure SATDrawInt (i: integer);
  212.     procedure SATDrawLong (l: longint);
  213.     function SATRand (n: integer): integer;
  214.     function SATRand10: integer;
  215.     function SATRand100: integer;
  216.     procedure SATReportStr (str: str255);
  217.     function SATQuestionStr (str: str255): Boolean;
  218.     function SATFakeAlert (s1, s2, s3, s4: Str255; nButtons, defButton, cancelButton: integer;{}
  219.                                     t1, t2, t3: Str255): integer;
  220.     procedure CheckNoMem (p: Ptr); {If the Ptr is nil, out of memory emergency exit}
  221.     procedure SATSetMouse (where: point);
  222.     procedure SATInitToolbox;
  223. {Pattern utilities}
  224.     procedure SATPenPat (SATpat: SATPatHandle);
  225.     procedure SATBackPat (SATpat: SATPatHandle);
  226.     function SATGetPat (patID: integer): SATPatHandle;
  227.     procedure SATDisposePat (SATpat: SATPatHandle);
  228. {Menu bar utilities}
  229.     procedure SATShowMBar (wind: WindowPtr);
  230.     procedure SATHideMBar (wind: WindowPtr);
  231. {PICT utilities}
  232.     procedure SATGetandDrawPICTRes (id: integer);
  233.     procedure SATGetandDrawPICTResInRect (id: integer; var frame: Rect);
  234.     procedure SATGetandCenterPICTResInRect (id: integer; var frame: Rect);
  235. {Sound}
  236.     procedure SATSoundInit; {Called from SATInit}
  237.     procedure SATSoundPlay (TheSound: Handle; Priority: integer; CanWait: boolean);
  238.     procedure SATSoundEvents; {Call this once in a while when not calling SATRun often}
  239.     procedure SATSoundShutup; {Silence, dispose of sound channel}
  240.     procedure SATSoundOn;
  241.     procedure SATSoundOff;
  242.     function SATSoundDone: Boolean; {Any sound going on ?}
  243.     function SATGetSound (sndId: integer): handle;        { To load a sound and get a handle for SATSoundPlay }
  244.     function SATGetNamedSound (name: Str255): Handle; { Same but using resource names }
  245.     procedure SATDisposeSound (theSnd: handle);
  246. {Multi-channel sound routines}
  247.     function SATSoundInitChannels (num: integer): integer;
  248.     function SATSoundDoneChannel (chanNum: integer): Boolean;
  249.     procedure SATSoundPlayChannel (theSound: Handle; chanNum: integer);
  250.     procedure SATSoundReserveChannel (chanNum: integer; reserve: Boolean);
  251.     procedure SATSoundShutupChannel (chanNum: integer);
  252.     procedure SATPreloadChannels;
  253. {Experimental, likely to be renamed/removed/changed:}
  254.     procedure SATSoundPlay2 (theSound: Handle; priority: integer; canWait, skipIfSame: Boolean);
  255.     procedure SATSoundPlayEasy (theSound: Handle; canWait: Boolean);
  256. {More multi-channel:}
  257.     function SATGetNumChannels: integer;
  258.     function SATGetChannel (chanNum: integer): Ptr;
  259. {Customization}
  260.     procedure SATSetSoundInitParams (params: Longint);
  261.  
  262. implementation
  263. end.